<?
include_once("./_common.php");

auth_check($auth[$sub_menu], "r");

$token = get_token();


$g4[title] = "방문일지 관리";
include_once("./admin.head.php");

/*--- 페이징 ---*/
$sql0 = "select count(*) as cnt from visit_record";
$row0 = sql_fetch($sql0);
$total_count = $row0['cnt'];

$rows = 10;
$total_page = ceil($total_count / $rows);
if($page == "") $page = 1;
$from_record = ($page -1) * $rows;

$sqlp = "select * from visit_record limit $from_record, $rows ";
$result = sql_query($sqlp);
$pagelist = get_paging2($rows, $page, $total_page, "$_SERVER[PHP_SELF]?$qstr&bo_table=visit&page=");

/*--- 지점명 가지고오기 ---*/
$sql = "select wr_1 from g4_write_branch order by wr_1 ASC";
$rst = sql_query($sql);
while($row = mysql_fetch_assoc($rst)) {
	$store[] = $row;
}

/*--- 방문자 가지고오기 ---*/
$sql1 = "select vi_name1 from visit_record group by vi_name1 order by vi_name1 ASC";
$rst1 = sql_query($sql1);
while($row1 = mysql_fetch_assoc($rst1)) {
	$name1[] = $row1;
}
$sql2 = "select * from visit_record ";

if ( $select_store ){
	$sql2 .= " where vi_store= '$select_store' ";
	
}
$sql2 .= "order by id DESC limit $from_record, $rows";

/*--- 리스트 출력 ---*/

$rst2 = sql_query($sql2);
while($row2 = mysql_fetch_assoc($rst2)) {
	$li[] = $row2;
}
$write_href = "./m_visit_insert.php?bo_table=$bo_table";

$write_pages = get_paging($config[cf_write_pages], $page, $total_page, "./m_visit_list.php?bo_table=$bo_table".$qstr."&page=");

$list_href = '';
$prev_part_href = '';
$next_part_href = '';


$nobr_begin = $nobr_end = "";
if (preg_match("/gecko|firefox/i", $_SERVER['HTTP_USER_AGENT'])) {
	$nobr_begin = "<nobr style='display:block; overflow:hidden;'>";
	$nobr_end   = "</nobr>";
}


?>
<br />
<style>

table.p_t {width:100%;}
table.p_t tr {line-height:24px;}
table.p_t th {background:url(/test/manage/imgs/tit_bg.gif) repeat-x;height:38px;color:white;line-height:16px;font-weight:normal;}
table.p_t th {border-bottom:1px solid #CCCCCC}
table.p_t td {border-bottom:none;}
table.p_t td {text-align:center;height:30px;}
table.p_t td a {color:black}
.mb15 {margin-bottom:15px;}
.board_page { clear:both; text-align:center; margin:3px 0 0 0; }
.board_page a:link { color:#777; }

</style>
<?=subtitle("방문일지 관리")?>

	
	<br />
	<div class="select_store_wrap" style="overflow:hidden;">
		<form name=fsearch method=get>
		<input type='hidden' name='bo_table'   value='<?=$bo_table?>'>
		<div style="float:left">
			<select name="select_store" class="select_store">
			<option value="all">전체지점</option>
			<?php
			for($i = 0; $i < count($store); $i += 1) { ?>
			<option value="<?php echo $store[$i]['wr_1']?>"><?php echo $store[$i]['wr_1']?></option>
			<? } ?>
			</select>
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			
			<input type=image src="./img_btn/search_btn.gif" align=absmiddle></td>
		</div>
		</form>
		<div style="float:right">
			<img src="./img_btn/excel_btn.gif" class="excel_btn" style="cursor:pointer;vertical-align:bottom" title="엑셀출력" />
			&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			<!--img src="<?php echo $g4['path']?>/test/manage/imgs/print_btn.gif" class="print_btn" style="cursor:pointer;vertical-align:bottom" title="프린트하기" /-->
			
		</div>
	</div>
	<script>
	$(".excel_btn").click(function() {
		
		var eb1 = $(".select_store").val();
		
		location.replace("./mv_excel.php?eb1=" + eb1 );
	});
	/*
	$(".print_btn").click(function() {
		alert("프린트 출력기능 작업중");
	});
	*/
	
	</script>
	<br />
	
	<table class="board_list" cellpadding="0" cellspacing="0" border="0" style="text-align: center;">
		<col width="200"/>
		<col width="130"/>
		<col width="130"/>
		<col width="180"/>
		<col width="130"/>
		<tr>
		<th>방문일자</th>
		<th>구분</th>
		<th>방문자</th>
		<th>점명</th>
		<th>점주명</th>
		</tr>
		<?php
		for($i = 0; $i < count($li); $i++) {
			$bg = $i%2 ? 0 : 1;
		?>
		<tr class="bg<?=$bg?>">
		
		<td><a href="<?php echo $g4['path']?>adm/adm_new/m_visit_view.php?bo_table=visit&id=<?php echo $li[$i]['id']?>"><?php echo $li[$i]['vi_date']?></a></td>
		<td><?php echo $li[$i]['vi_flag']?></td>
		<td><?php echo $li[$i]['vi_name1']?></td>
		<td><?php echo $li[$i]['vi_store']?></td>
		<td><?php echo $li[$i]['vi_name2']?></td>
		
		</tr>
		
		<? } ?>
		
		
	</table>
<!-- 
	<div class="re_list">
	</div>
	<br />
	<style>
	div.jj_btnwrap {position:relative;height:35px;width:100%}
	div.jj_btn_subwrap {overflow:hidden;position:absolute;top:0;right:0}
	div.jj_btnwrap div {float:left;margin-left:7px}
	div.jj_btn_box_on {width:35px;height:35px;border:1px solid #ccc;background-color:#fbf8ee}
	div.jj_btn_box_off {width:35px;height:35px;border:1px solid #ccc;}
	p.jj_on_font {vertical-align:middle;padding:0;margin:0;font-weight:bold;color:black;font-size:13px;margin-top:8px;}
	p.jj_off_font {vertical-align:middle;padding:0;margin:0;font-weight:bold;color:#666;font-size:13px;margin-top:8px;}
	</style>

	<div class="jj_btnwrap" id="cl_jj_bt_hide">
		<div class="jj_btn_subwrap">
			<?php echo $pagelist;?>
		</div>
	</div>
	-->
	<div class="re_list">
	</div>
	<div style="float:right">
		<?php if($is_admin) { ?>
			<a href="<?php echo $write_href ?>"><img src="./img_btn/btn_write.gif" alt="글쓰기" /></a>
		<? } ?>
	</div>
	<!-- 페이지 -->
    <div class="board_page" >
        <? if ($prev_part_href) { echo "<a href='$prev_part_href'><img src='./img_btn/page_search_prev.gif' border='0' align=absmiddle title='이전검색'></a>"; } ?>
       
        <?
        // 기본으로 넘어오는 페이지를 아래와 같이 변환하여 이미지로도 출력할 수 있습니다.
        //echo $write_pages;
        $write_pages = str_replace("처음", "<img src='./img_btn/page_begin.gif' border='0' align='absmiddle' title='처음'>", $write_pages);
        $write_pages = str_replace("이전", "<img src='./img_btn/page_prev.gif' border='0' align='absmiddle' title='이전'>", $write_pages);
        $write_pages = str_replace("다음", "<img src='./img_btn/page_next.gif' border='0' align='absmiddle' title='다음'>", $write_pages);
        $write_pages = str_replace("맨끝", "<img src='./img_btn/page_end.gif' border='0' align='absmiddle' title='맨끝'>", $write_pages);
        //$write_pages = preg_replace("/<span>([0-9]*)<\/span>/", "$1", $write_pages);
        $write_pages = preg_replace("/<b>([0-9]*)<\/b>/", "<b><span style=\"color:#4D6185; font-size:12px; text-decoration:underline;\">$1</span></b>", $write_pages);
        ?>
        <?=$write_pages?>
        <? if ($next_part_href) { echo "<a href='$next_part_href'><img src='./img_btn/page_search_next.gif' border='0' align=absmiddle title='다음검색'></a>"; } ?>
    </div>
<form name='fpost' method='post'>
<input type='hidden' name='select_store'   value='<?=$select_store?>'>
<input type='hidden' name='bo_table'   value='<?=$bo_table?>'>
</form>
<?
if ($select_store)
	echo "<script type='text/javascript'>document.fsearch.select_store.value = '$select_store';</script>\n";

include_once("../admin.tail.php");
?>
